<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
	<style type="text/css">
		*{
			margin: 0;
			padding: 0;
		}
		.tabHeader{
			display: flex;
		}
		span{
			width: 200px;
		}
		
		.tabContent{
			text-align: center;
		}
		.tab{
			width: 600px;
			height: 300px;
			border: 1px solid #000;
		}
		.tabContent .item {
     		 display: none;
    	}

   		.tabContent .item.active {
     		display: block;
    	}
    	.head{
    		background: orange;
    	}
	</style>
</head>
<body>
<div class="tab">
	<div class="tabHeader"><span class="head">标题1</span><span>标题2</span><span>标题3</span></div>
	<div class="tabContent">
		<div class="item active">内容1</div>
		<div class="item">内容2</div>
		<div class="item">内容3</div>
	</div>
</div>

<script type="text/javascript">
	let span = document.querySelectorAll('span')
	let item = document.querySelectorAll('.item')
	for(let i = 0; i < span.length; i++){
		span[i].onclick = function(){
			document.querySelector('.active').classList.remove('active')
			document.querySelector('.head').classList.remove('head')
			span[i].classList.add('head')			
			item[i].classList.add('active')

		}
	}
</script>
</body>
</html>